package org.gp.tringes;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;

public class GestorIGVenderPerro {
	
	private static GestorIGVenderPerro miGestorIGVenderPerro = new GestorIGVenderPerro();
	
	private GestorIGVenderPerro(){}
	
	public static GestorIGVenderPerro getGestorIGVenderPerro(){
		return miGestorIGVenderPerro;
	}
	
	public Iterator<String> getDuenos(String pNumFederado){
		ResultSet rs;
		ArrayList<String> lista = new ArrayList<String>();
		try {
			rs = GestorBD.getInstance().consulta("select numFederado FROM dueno WHERE numFederado!='"+pNumFederado+"' and activo=1");
			
			while(rs.next()){
				lista.add(rs.getString("numFederado"));
			}
			
			GestorBD.getInstance().cerrarConsulta(rs);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return lista.iterator();
	}
	
	public Boolean existeVenta(String pIdPerro) throws SQLException{
		
		ResultSet rs = GestorBD.getInstance().consulta("select * from transpendientes where idPerro='"+pIdPerro+"'");
			
		Boolean result = rs.next();
		GestorBD.getInstance().cerrarConsulta(rs);
		if(result){
			return true;
		}else{
			return false;
		}
	}
	
	public void anadirVenta(String pVend, String pComp, String pIdPerro, int pPrecio){
		try{
			GestorBD.getInstance().insertar("insert into transpendientes (idVend,idComp,idPerro,Precio) values ('"+pVend+"','"+pComp+"','"+pIdPerro+"',"+pPrecio+")");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}

